home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / misc / emu / Easy1541.lha / Easy1541 / dev / Examples / IECCmd.c next >
C/C++ Source or Header  |  1996-09-02  |  2KB  |  110 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <exec/exec.h>
  5. #include <exec/execbase.h>
  6. #include <exec/memory.h>
  7. #include <proto/exec.h>
  8. #include <proto/dos.h>
  9.  
  10. #include <iec/iec.h>
  11.  
  12. //----------------------------------------
  13. //IECCmd 1.0
  14. //
  15. //Sends a command to the 1541
  16. //OPEN 15,8,15,"<cmd>" : CLOSE 15
  17. //
  18. //----------------------------------------
  19.  
  20.  
  21. struct iecbase *IECBase;
  22.  
  23. struct RDArgs *rda;
  24. LONG argv[2]={0,0};
  25. char device=8;    //Default device #
  26. char* string;    //Command string to send
  27.  
  28.  
  29. char Version[]="$VER:IECCmd 1.0 (03.08.96) by Fabrizio Farenga";
  30.  
  31. //******************************************
  32. // Send a null-terminated string to the 1541
  33. //******************************************
  34. void SendString(char* string)
  35. {
  36. int t;
  37. for (t=0;string[t]!=0;t++) CIOut(string[t]); 
  38. }
  39.  
  40.  
  41. void SendCMD(void)
  42. {
  43.     Listen(device);
  44.     Second(CMD_OPEN+15);
  45.  
  46.     if (IECBase->iec_ST==ST_OK)
  47.         {
  48.         UnListen();
  49.  
  50.         Listen(device);
  51.         Second(CMD_DATA+15);
  52.         SendString(string);    //Send the command string to the 1541
  53.         UnListen();
  54.  
  55.         Listen(device);
  56.         Second(CMD_CLOSE+15);
  57.         UnListen();
  58.  
  59.         }
  60.     else
  61.         {
  62.         printf ("\n?DEVICE NOT PRESENT\n\n");
  63.         }
  64.  
  65.  
  66. }
  67.  
  68.  
  69. void main(void)
  70. {
  71.  
  72. if ((rda = ReadArgs("Command/A,Device/N",argv,NULL)) != NULL)
  73.     {
  74.     if (argv[0]!=0) string=(char*)argv[0];        //Command string
  75.     if (argv[1]!=0) device=*(LONG *)argv[1];    //device number
  76.     }
  77.     else
  78.     {
  79.     printf ("Required argument missing!\n\n");
  80.     return;
  81.     }
  82.  
  83. if ((device<4)||(device>30))
  84.     {
  85.     printf ("\n?DEVICE NOT PRESENT\n\n");
  86.     return;
  87.     }
  88.  
  89. IECBase = (struct iecbase*)OpenLibrary("iec.library",0L);
  90.  
  91. if (IECBase!=0)
  92.     {
  93.  
  94.     SendCMD();    //Send the command to the 1541
  95.  
  96.     CloseLibrary((struct Library*)IECBase);
  97.     }
  98. else
  99.     {
  100.     printf ("Can't open iec.library\n");
  101.     return;
  102.     }
  103.  
  104.     if (rda!=NULL) FreeArgs(rda);
  105.  
  106.  
  107. }
  108.  
  109.  
  110.